package com.yike.user.controller.feign;

import com.yike.common.base.BaseController;
import com.yike.common.exception.BusinessException;
import com.yike.user.api.vo.MerchantFeignVo;
import com.yike.user.api.vo.ShopFeignVo;
import com.yike.user.entity.Merchant;
import com.yike.user.entity.Shop;
import com.yike.user.mapper.MerchantMapper;
import com.yike.user.mapper.ShopMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 权限表 控制器
 *
 * @author yike
 * @since 2023-08-24
 */
@Slf4j
@RestController
@RequestMapping("/feign/merchant")
@ApiIgnore
public class MerchantFeignController extends BaseController {

    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private MerchantMapper merchantMapper;

    /**
     * 获取当前url所需权限
     */
    @GetMapping("/getMerchantByShopId")
    public MerchantFeignVo getMerchantByShopId(Long shopId) throws Exception {
        Shop shop = shopMapper.selectById(shopId);
        if (shop == null || shop.getMerchantId() == null) {
            throw new BusinessException("商家信息异常");
        }
        Merchant merchant = merchantMapper.selectById(shop.getMerchantId());
        if (merchant == null) {
            throw new BusinessException("商家信息异常");
        }
        MerchantFeignVo merchantFeignVo = new MerchantFeignVo();
        BeanUtils.copyProperties(merchant, merchantFeignVo);
        return merchantFeignVo;
    }

}

